﻿namespace SRM.DataObjects
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;

    /// <summary>
    /// Summary description for SRM_Language
    /// </summary>
    [DataObjectAttribute(true)]
    public class SRM_Language
    {

        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public static DataTable GetLanguageProficiency(string applicantKey)
        {
            DataTable dtResult = null;

            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = conn.CreateCommand();
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                cmd.CommandText = string.Format("SELECT * FROM SRM_ApplicantLanguage_Tbl WHERE ApplicantKey = {0};", applicantKey);
                da.Fill(ds);

                dtResult = ds.Tables[0];
            }

            return dtResult;
        } // public static DataTable GetLanguageProficiency(string applicantKey)

        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "INSERT INTO SRM_ApplicantLanguage_Tbl (ApplicantKey, Language, Ability, Proficiency) VALUES (@ApplicantKey,@Language,@Ability,@Proficiency);";
                cmd.Parameters.AddWithValue("@ApplicantKey", applicantKey);
                cmd.Parameters.AddWithValue("@Language", language);
                cmd.Parameters.AddWithValue("@Ability", ability);
                cmd.Parameters.AddWithValue("@Proficiency", proficiency);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)

        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public static void DeleteLanguageProficiency(string languageKey)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "DELETE FROM SRM_ApplicantLanguage_Tbl WHERE LanguageKey = @LanguageKey;";
                cmd.Parameters.AddWithValue("@LanguageKey", languageKey);
                
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)

        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public static void UpdateLanguageProficiency(string languageKey, string language, string ability, string proficiency)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = @"
UPDATE  SRM_ApplicantLanguage_Tbl 
SET     Language = @Language, 
        Ability = @Ability, 
        Proficiency = @Proficiency 
WHERE   LanguageKey = @LanguageKey;";

                cmd.Parameters.AddWithValue("@LanguageKey", languageKey);
                cmd.Parameters.AddWithValue("@Language", language);
                cmd.Parameters.AddWithValue("@Ability", ability);
                cmd.Parameters.AddWithValue("@Proficiency", proficiency);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)

    }
}